package jcode.code;

public class LinkedList<T> {
    private static class Node<T>{
        T  item;
        Node next;
        public Node(T item, Node next){
            this.item = item;
            this.next = next;
        }
         
    }

    private Node<T> head;
    private Node<T> tail;
    private int size;

    public LinkedList() {
        head = null;
        tail = null;
        size = 0;
    }
    public void add(int index, T t){
        checkIndex(index);
         
        Node pre = head;
        for(int i = 0; i < index; i++){
            pre = pre.next;
        }
        pre.next = new Node<>(t, pre.next);
        size++;

    }
    public void add(T data) {
        Node<T> node = new Node<T>(data, null);
        if (head == null) {
            head = node;
            tail = node;
        } else {
            tail.next = node;
            tail = node;
        }
        size++;
    }
    
}
